package com.cryrabbit.bmbhome.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageButton;

import com.baidu.mapapi.SDKInitializer;
import com.cryrabbit.bmbhome.R;
import com.cryrabbit.bmbhome.adapters.MyAdapter;
import com.cryrabbit.bmbhome.adapters.MyPage;
import com.cryrabbit.bmbhome.utils.icon;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    ImageButton button;
    View view1,view2;
    GridView gridView,gridView2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_main);
        initView();
        initGridView();
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0:
                        Intent intent=new Intent(MainActivity.this,WebActivity.class);
                        intent.putExtra("url","http://www.bmbhome.org/article");
                        startActivity(intent);
                        break;
                    case 1:
                        Intent intent1=new Intent(MainActivity.this,WebActivity.class);
                        intent1.putExtra("url","http://www.bmbhome.org/chair");
                        startActivity(intent1);
                        break;
                    case 2:
                        Intent intent2=new Intent(MainActivity.this,WebActivity.class);
                        intent2.putExtra("url","http://www.bmbhome.org/question");
                        startActivity(intent2);
                        break;
                    case 3:
                        Intent intent3=new Intent(MainActivity.this,WebActivity.class);
                        intent3.putExtra("url","http://www.bmbhome.org/findDoctor");
                        startActivity(intent3);
                        break;
                }
            }
        });
        gridView2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0:
                        startActivity(new Intent(MainActivity.this,SportActivity.class));
                        break;
                    case 1:
                        Intent intent=new Intent(MainActivity.this,VoiceActivity.class);
                        startActivity(intent);
                        break;
                    case 2:
                        startActivity(new Intent(MainActivity.this,MobileActivity.class));
                        break;
                }
            }
        });
    }
    public void initView(){
        LayoutInflater inflater=getLayoutInflater();
        view1=inflater.inflate(R.layout.group_one,null);
        view2=inflater.inflate(R.layout.group_two,null);
        ViewPager viewPager=(ViewPager)findViewById(R.id.viewpager);
        TabLayout tabLayout=(TabLayout)findViewById(R.id.tablayout);
        tabLayout.setTabTextColors(Color.DKGRAY,Color.WHITE);
        List<View> views=new ArrayList<>();
        views.add(view1);
        views.add(view2);
        List<String> titles=new ArrayList<>();
        titles.add("情绪管理");
        titles.add("身体管理");
        viewPager.setAdapter(new MyPage(views,titles));
        tabLayout.setupWithViewPager(viewPager);
    }
    public void initGridView(){
        gridView=(GridView)view1.findViewById(R.id.grid);
        List<icon> icons=new ArrayList<>();
        icons.add(new icon(R.drawable.duwenzhang,"读文章  "));
        icons.add(new icon(R.drawable.tingjiangzuo ,"听讲座  "));
        icons.add(new icon(R.drawable.zuoceshi,"做测试  "));
        icons.add(new icon(R.drawable.zhaoyisheng,"找医生  "));
        MyAdapter myAdapter=new MyAdapter(icons,this,0);
        gridView.setAdapter(myAdapter);
        gridView2=(GridView)view2.findViewById(R.id.grid2);
        List<icon> icons1=new ArrayList<>();
        icons1.add(new icon(R.drawable.paobu,"跑 步"));
        icons1.add(new icon(R.drawable.jiankangcao,"正念修习"));
        icons1.add(new icon(R.drawable.shouji,"手机使用情况"));
        gridView2.setAdapter(new MyAdapter(icons1,this,1));
    }
}
